package admin

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"zhuandan/data_source"
	"zhuandan/models"
)

func Laiyuans(ctx *gin.Context) {
	request := ProcuresBody{}
	ctx.ShouldBind(&request)
	var laiyuan []models.Laiyuan
	data_source.Db.Find(&laiyuan)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    laiyuan,
		"msg":     "ok",
	})
	return
}

type Laiyuanody struct {
	ID   int64  `gorm:"column:id" json:"id"`
	Name string `json:"name" from:"name"`
}

func Laiyuanadd(ctx *gin.Context) {
	request := Laiyuanody{}
	ctx.ShouldBind(&request)
	name := request.Name
	ly := models.Laiyuan{
		Name: name,
	}
	data_source.Db.Create(&ly)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return
}
func Laiyuanupdate(ctx *gin.Context) {
	request := Laiyuanody{}
	ctx.ShouldBind(&request)
	id := request.ID
	name := request.Name
	ly := models.Laiyuan{
		Name: name,
	}
	data_source.Db.Where("id = ?", id).Updates(&ly)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return
}
func Laiyuandel(ctx *gin.Context) {
	request := Laiyuanody{}
	ctx.ShouldBind(&request)
	id := request.ID

	data_source.Db.Where("id = ?", id).Delete(&models.Laiyuan{})
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return
}
